/*
 * @Project Name: 11
 * @File Name: SwaggerPlugin.java
 * @Package Name: org.mybatis.generator.plugins
 * @Date: 2017年5月26日上午11:43:54
 * @Creator: wangyulong-910
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package org.amado.generator.plugins;

import java.util.List;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.TopLevelClass;

/**
 * TODO
 * @author wangyulong-910
 * @date 2017年5月26日上午11:43:54
 * @see
 */
public class SwaggerPlugin extends PluginAdapter {

	@Override
	public boolean validate(List<String> warnings) {
		return true;
	}

	public boolean modelFieldGenerated(Field field, TopLevelClass topLevelClass, IntrospectedColumn introspectedColumn,
			IntrospectedTable introspectedTable, ModelClassType modelClassType) {
		String remarksComent = introspectedColumn.isNullable()?"//可以为空":"//不能为空";
		if (introspectedColumn.getRemarks() != null && introspectedColumn.getRemarks().trim().length() > 0) {
			field.addAnnotation("@ApiModelProperty(value = \"" + introspectedColumn.getRemarks() + "\")"+remarksComent);
		}else{
			field.addAnnotation("@ApiModelProperty(value = \"" + field.getName() + "\")"+remarksComent);
			introspectedColumn.isNullable();
		}
		topLevelClass.addImportedType("io.swagger.annotations.ApiModelProperty");
		return true;
	}
}
